import React from 'react';
import './index.less';
import base from '../../../util/base';
import * as type from '../../../constants/type';
import * as FormUtil from '../../../util/formUtil';
import { WeaPopoverHrm } from 'ecCom';
import { WeaLocaleProvider } from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;
export default class Main extends  React.Component {

  getOperator(operators, str) {
    let operatorArr = operators;
    if( operatorArr.length > 10) {
      operatorArr = operatorArr.slice(0,10);
    }
    return (
      <p className='operator-text'>
        <span className='next-operator'>{getLabel(515204,'下一节点操作者:')} </span>
        { operatorArr.length > 0 && operatorArr.map( (item,index) => {
              let hasAgent = item.isbeAgent == 'true' ? true : false;
              if(hasAgent) { //有代理的情况
                if(index == 9) {
                  return (<a  href={`javaScript:openhrm(${item.operatorid});` }  
                              onClick={e => window.pointerXY(e)} 
                              className="operator" 
                              style={{marginLeft: '10px'}}>{item.beagentname + '->' + item.operatorname  + '...'}
                          </a>)
                } else {
                  return (<a  href={`javaScript:openhrm(${item.operatorid});`}  
                              onClick={e => window.pointerXY(e)} 
                              className="operator" 
                              style={{marginLeft: '10px'}}>
                                {item.beagentname + '->' + item.operatorname}
                        </a>)
                }
              } else {
                if(index == 9) {
                  return (<a  href={`javaScript:openhrm(${item.operatorid});`}  
                              onClick={e => window.pointerXY(e)} 
                              className='operator' 
                              style={{marginLeft: '10px'}}> 
                              {item.operatorname + '...'}
                          </a>)
                } else {
                  return (<a  href={`javaScript:openhrm(${item.operatorid});`}  
                              onClick={e => window.pointerXY(e)} 
                              className='operator' 
                              style={{marginLeft: '10px'}}> 
                              {item.operatorname}
                          </a>)
                }
              }
            })
        }
        { operatorArr.length == 0 && <span style={{marginLeft: '5px'}}>{ str}</span>}
      </p>  
    ) 
  }

  //跳转至流程图Tab 
  jumpWfMap = () => {
    base.globalStore.setTabKey('pic');
    base.globalStore.controlDialogVisible(type.ENSURE_SUBMIT, false);
    if(base.globalStore.submitParam.requestid != -1) {
      base.smartGuessWfStore.openForecastFunc(true);
      FormUtil.switchFormTab('pic', false); //跳转tab
      base.smartGuessWfStore.clickSmartBtn();
    }
  }

  render() {
    const { promptInfo } = this.props;
    const { isFree, openAutoForecast='0' } = base.globalStore.commonParam;
    let canGetNextNode = false;
    if(promptInfo.isSuccess) {
      canGetNextNode = true;
    }
    let str = promptInfo.titlesuffix || ' ';
    while(str && str.indexOf('span') > -1) {
      str = str.replace('<span>', '').replace('</span>', ' ');
    } 
    let nextNodeStr = str;
    return (
      <div className='content-box' style={{fontSize: '14px'}}>
        <p style={{paddingBottom: '5px'}}>{getLabel(22161, '确定要提交吗？')}</p>
        {
          canGetNextNode ? <p className={'next-node-name'} 
                               style={{paddingBottom: '5px'}}> 
                          {getLabel(515203,'下一节点')}  {nextNodeStr}
                          </p>
            :
            <p>{getLabel(515207, '下一节点无法预知')}</p>
        }
        {
          canGetNextNode 
          && promptInfo.operators 
          && promptInfo.operators.length > 0  
          && this.getOperator(promptInfo.operators)
        }
        {
          (canGetNextNode && !promptInfo.operators)  
          || (canGetNextNode && promptInfo.operators.length == 0)
          && this.getOperator([], nextNodeStr)
         }
        {
          isFree != '1'  
          && openAutoForecast == '1' 
          && <a
                className={'forcast-link'} 
                onClick={this.jumpWfMap} 
                style={{fontSize: '12px'}}
             > 
                {getLabel(515205, '点击这里查看后续流转预测')}
                <i className="icon-coms-right" />
          </a>
        }
      </div>
    )
  }
}